/*
 * Copyright (C) 2003-2011 eXo Platform SAS.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see<http://www.gnu.org/licenses/>.
 */
package khiem.gwt.demo.gadgetDesktop.client.view;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Created by The eXo Platform SAS
 * Author : eXoPlatform
 *          exo@exoplatform.com
 * Jun 30, 2011  
 */
public class DesktopView extends Composite {
  
  public DesktopView() {
    VerticalPanel mainPanel = new VerticalPanel();
    initWidget(mainPanel);
    setWidth("100%");
    setHeight("100%");
    
    // create the menu
    HorizontalPanel gadgetsMenu = new HorizontalPanel();
    mainPanel.add(gadgetsMenu);
    mainPanel.setCellHorizontalAlignment(gadgetsMenu, HasHorizontalAlignment.ALIGN_CENTER);
    
    // add items to the menu
    gadgetsMenu.add(new Label("Gadget-1"));
    gadgetsMenu.add(new Label("Gadget-2"));
    gadgetsMenu.add(new Label("Gadget-3"));
    
    // create the tab panel
    TabPanel gadgetTabs = new TabPanel();
    mainPanel.add(gadgetTabs);
    mainPanel.setCellHeight(gadgetTabs, "100%");
    gadgetTabs.setWidth("100%");
    gadgetTabs.setHeight("100%");
    
    // create the tabs and pages
    gadgetTabs.add(createPage(), "Tab-1");
    gadgetTabs.add(new Label("Page-2"), "Tab-2");
    
    gadgetTabs.selectTab(0);
  }
  
  /**
   * Creates the page, each page relates to a tab and has 3 columns
   * @return the HorizontalPanel object represents page
   */
  public HorizontalPanel createPage() {
    // create horizontal panel to how columns
    HorizontalPanel page = new HorizontalPanel();
    page.setWidth("100%");
    page.setHeight("100%");
    page.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
    
    // add columns
    createColumn(page, 0);
    createColumn(page, 1);
    createColumn(page, 2);
    return page;
  }
  
  public void createColumn(HorizontalPanel page, int columnNumber) {
    // create a column with a flow panel
    FlowPanel column = new FlowPanel();
    page.add(column);
    page.setCellWidth(column, "33%");
    page.setCellHeight(column, "100%");
    column.setHeight("100%");
    
    column.add(new Label("gadget1"));
    column.add(new Label("gadget2"));
    column.add(new Label("gadget3"));
  }
  
}
